//
//  CodeGroup.m
//  ECGDiagnosisCodeExchanger
//
//  Created by jia yu on 2021/11/12.
//

#import "CodeGroup.h"
#import "CodeItem.h"

@implementation CodeGroup
@synthesize key;
@synthesize name;
@synthesize items;

-(id)initWithName:(NSString *)_key items:(NSArray *)_itemsArray{
    self = [super init];
    if (self){
        key = _key;
        NSRange range = [key rangeOfString:@" "];
        if (range.length > 0 && range.location > 0){
            name = [key substringFromIndex:range.location + range.length];
        }else{
            name = key;
        }
        items = [[NSMutableArray alloc] init];
        for (NSString *inString in _itemsArray){
            NSArray *array = [inString componentsSeparatedByString:@"-"];
            if (2 != array.count){
                continue;
            }
            CodeItem *item = [[CodeItem alloc] init];
            item.interpretationCode = [array.firstObject integerValue];
            item.itemString = [NSString stringWithFormat:@"%@", array.lastObject];
            [items addObject:item];
        }
    }
    return self;
}
@end
